<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Danh sách các Tour</title>
</head>

<body>
<?php
	include("include/db_connect.php");
	
	$query = mysql_query("Select * from dc_tour");
	$rowTotal = mysql_num_rows($query);
	$rowPage = 1;
	$pageNumber = ceil($rowTotal/$rowPage);
	$pageIndex = $_REQUEST["page"];
	if($pageIndex==null||$pageIndex=="") $pageIndex=1;
	$offset = ($pageIndex-1)*$rowPage;
	
	$query1 = mysql_query("Select * from dc_tour LIMIT $offset,$rowPage");
?>
<table width="100%" border="0">
  <caption>
    Danh sách các Tour
  </caption>
  <tr>
    <td>ID</td>
    <td>Tên tour</td>
    <td>Trạng thái</td>
	<td colspan="">Thao tác</td>
  </tr>
  <?php while($row = mysql_fetch_array($query1)){ ?>
  <tr>
    <td><?php echo $row[0]; ?></td>
    <td><?php echo $row[1]; ?></td>
    <td>
    <?php
    	if($row[9]==0) echo "Chưa duyệt";
    	else if($row[9]==1) echo "Đã duyệt"; 
    	else if($row[9]==2) echo "Hết hạn"; 
    ?>
    </td>
	<td><a href="tourDetail.php?id=<?php echo $row[0]; ?>&page=<?php echo $pageIndex;?>">Chi tiết</a></td>
	<td><a href="removeTour.php?id=<?php echo $row[0]; ?>&page=<?php echo $pageIndex;?>">Xóa Tour</a></td>
  </tr>
  <?php } ?>
</table>
<form action="tourUpdateState.php" method="post">
	<input type="submit" class="submit button" name="btnUpdateTour" value="Cập nhật thời hạn của Tour" />
</form>
<p>
<a href="tourList.php?page=1">[First] </a>
<?php

if($pageIndex!=1) echo "<a href='tourList.php?page=".($pageIndex-1)."'>[Previous] </a>";
for($page=1;$page<=$pageNumber;$page++)
{
	if($page==$pageIndex) echo "<strong>".$page."</strong> ";
	else echo "<a href='tourList.php?page=".$page."'>".$page."</a> ";
}
if($pageIndex!=$pageNumber) echo "<a href='tourList.php?page=".($pageIndex+1)."'>[Next] </a>";
?>
<a href="tourList.php?page=<?php echo $pageNumber; ?>">[Last]</a>
</p>
</body>
</html>
